const debug = true
const _baseURL = debug?'http://127.0.0.1:3000' :'https://www.doupaopao.club'

const http = function(method, url, data, type = 1) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: _baseURL + url, //仅为示例，并非真实接口地址。
			data: data,
			method: method,
			header: {
				// 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
				token: uni.getStorageSync('token') || ''
			},
			timeout: 3000,
			
			
			
			success: (res) => {
				if (res.data.code !== 200) {
					if (res.data.code  == 501) {
						uni.reLaunch({
							url: '/pages/logon/index'
						})
						return
					}
					return reject(res)
				}
				return resolve(res.data.data)
			}
		});
	})
}

module.exports = http
